﻿global using YwhLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YwhCore
{
    public class BuildingService
    {
        /// <summary>
        /// 数据库获取建筑列表
        /// </summary>
        /// <returns></returns>
        public static QueryRsp<Building> Save(Building building)
        {
            QueryRsp<Building> rsp = new QueryRsp<Building>();

            ConfigService.Fsql.InsertOrUpdate<Building>().SetSource(building).ExecuteAffrows();

            return rsp;
        }

        public static QueryRsp<Building> List(int PageNumber, int PageSize, int phaseNo = 0)
        {
            long l = 0;
            QueryRsp<Building> query = new QueryRsp<Building>();
            if (phaseNo == 0)
            {
                query.Items = ConfigService.Fsql.Select<Building>().Count(out l).Page(PageNumber, PageSize).ToList();
            }
            else
            {
                query.Items = ConfigService.Fsql.Select<Building>().Where(f => f.PhaseNo == phaseNo).Count(out l).Page(PageNumber, PageSize).ToList();
            }
            query.Total = (int)l;
            return query;
        }

        public static QueryRsp<Building> Update(Building building)
        {
            QueryRsp<Building> rsp = new QueryRsp<Building>();

            ConfigService.Fsql.Update<Building>().Set(a => a.PhaseNo, 1).ExecuteAffrows();

            return rsp;
        }

        public static QueryRsp<Building> Delete(Building building)
        {
            QueryRsp<Building> rsp = new QueryRsp<Building>();

            ConfigService.Fsql.Delete<Building>().Where(x => x.BuildingNo == building.BuildingNo).ExecuteAffrows();

            return rsp;
        }
    }
}
